package com.example.activity_service.dao;

import com.example.activity_service.vo.Red;

import org.apache.ibatis.annotations.*;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import org.springframework.stereotype.Repository;

import javax.ws.rs.DELETE;
import java.util.Date;
import java.util.List;

@Mapper
@Repository
public interface Yssdao {
    @Select("select * from hongbao where status=1 and users=#{users}")
    List<Red>searchhb(int users);

    @Select("select * from hongbao where status=2 and users=#{users}")
    List<Red>searchsyhb(int users);

    @Select("select * from hongbao where status=3 and users=#{users}")
    List<Red>searchgqhb(int users);





    @Update("update hongbao set status=2 where id=#{id}")
    int updatezt(int id, int status);
    @Select("select * from hongbao where status=0 ")
    List<Red> cahwei();
    //根据时间比较改成过期红包
    @Update("update hongbao set status =3 where timedata<NOW()")
    int updateguoqi( );

    //活动次数
    @Select("select user_huodong from user_data where user_id=#{user_id}")
    int chacs(int user_id);

    //后台查所有红包
    @Select("select * from hongbao")
    List<Red>searchsuoyou();

    //后台删除红包
    @Delete("delete  from hongbao where id=#{id}")
    int deletehb(int id);

    //后台新增红包
    @Insert("insert into hongbao (preferentialway,parvalue,threshold,totalissued,users,collectiontime,timedata,status)values(#{preferentialway},#{parvalue},#{threshold},#{totalissued},#{users},NOW(),date_sub(NOW(),interval -30 day),'0') ")
    int tianjiahb(int preferentialway,String parvalue,String threshold,String totalissued,String users);

    //后台修改红包
    @Update("update hongbao set preferentialway=#{preferentialway},parvalue=#{parvalue},threshold=#{threshold},totalissued=#{totalissued} where id=#{id}")
    int updatehb(int id,int preferentialway,int parvalue,int threshold,int totalissued);
@Update("update hongbao set users=#{id} ,status=1 where id=#{juan}")
    void juan(String id, String juan);
}
